package com.yanqu.road.server.cmd.activity.doublespring.cross;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.DoubleSpringProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.doublespring.DoubleSpringActivityModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.S_DOUBLE_SPRING_CROSS_QUERY_USER_BASE,desc = "踏春游记-跨服返回-查询玩家基础数据")
public class DoubleSpringQueryUserFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DoubleSpringProto.DoubleSpringCrossQueryUserReqMsg reqMsg = DoubleSpringProto.DoubleSpringCrossQueryUserReqMsg.parseFrom(packet.getBytes());
        DoubleSpringProto.DoubleSpringServerToCrossQueryUserReturnReqMsg.Builder crossReqMsg = DoubleSpringProto.DoubleSpringServerToCrossQueryUserReturnReqMsg.newBuilder();
        crossReqMsg.setActivityId(reqMsg.getActivityId());
        crossReqMsg.setUserId(reqMsg.getUserId());
        crossReqMsg.setServerId(reqMsg.getServerId());
        //用userId查
        if (reqMsg.getQueryUserId() != 0) {
            UserBaseInfo userBaseInfo = UserMgr.getUserBaseInfo(reqMsg.getQueryUserId(), reqMsg.getQueryServerId());
            if (userBaseInfo != null) {
                crossReqMsg.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo));
            }
            crossReqMsg.setQueryUserId(reqMsg.getQueryUserId());
        }
        //用userAliasId查
        if (reqMsg.getQueryUserAliasId() != 0) {
            UserInfo userInfo = UserMgr.getUserInfoByAliasId(reqMsg.getQueryUserAliasId());
            if (userInfo != null) {
                UserBaseInfo userBaseInfo = UserMgr.parseUserBaseInfo(userInfo, reqMsg.getQueryServerId());
                crossReqMsg.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo));
                crossReqMsg.setQueryUserId(userInfo.getUserId());
            }
        }
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C_CROSS_DOUBLE_SPRING_QUERY_USER_BASE, crossReqMsg);
        GamePlayerMgr.sendPacket(0, pbMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
